<template>
    <el-dialog v-dialog title="审核" :close-on-click-modal="false"
        :visible.sync="visible" @close="handleClose" :center="true">

        <el-form :model="dataForm"  ref="dataForm" @keyup.enter.native="dataFormSubmit()"
            label-width="80px">
            <el-form-item label="标题">

                <el-input v-model="dataForm.title" placeholder="" :disabled="true" ></el-input>
            </el-form-item>
            <el-form-item label="总面积" >
             <el-input v-model="dataForm.totalArea" placeholder="" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="地址" >
               <el-input v-model="dataForm.address" placeholder="" :disabled="true"></el-input>
            </el-form-item>

            <el-form-item label="种植类型" >
               <el-input v-model="dataForm.type" placeholder="" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="共享期限" >
               <el-input v-model="dataForm.deadline" placeholder="" :disabled="true"></el-input>
            </el-form-item>

            <el-form-item label="审核意见">
                <el-input v-model="dataForm.checkReason" placeholder="输入审核意见" type="textarea"></el-input>
            </el-form-item>
           
        </el-form>

        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dataFormSubmit(1)">通过</el-button>
            <el-button type="primary" @click="dataFormSubmit(2)">拒绝</el-button>
            <el-button @click="visible = false">取消</el-button>
        </span>

    </el-dialog>
</template>
<script>
    import API from '@/api';
    import cloneDeep from 'lodash/cloneDeep';
    export default {
        data() {
            return {
                typeOptions: [],
                visible: false,
                dataForm: {
                    title: '',
                    totalArea: '',
                    address: '',
                    type: '',
                    deadline: '',
                    checkReason:''
                }
            };
        },
        methods: {
            handleClose() {
            this.dataForm = {};
            this.$refs['dataForm'].resetFields();
        },
       
        //- 初始化
        init(id) {
            this.visible = true;
            this.getDetail(id);
        },
        getDetail(id) {
            API.sharefarmland
                .lookFarmlandDetail({
                    id: id
                })
                .then((res) => {
                    console.log(res);
                    this.dataForm = res.result;
                });
        },

        //- 通过或拒绝
        dataFormSubmit(type) {
            if (type == 2 && this.dataForm.checkReason == '') {
                // 拒绝
                this.$message.error('请填写审核意见，并说明拒绝原因');
                return;
            }

            var params = {
                checkReason: this.dataForm.checkReason,
                id: this.dataForm.id,
                checkStatus:type // 1:已通过;2:未通过
            };
        
            API.sharefarmland.approveOrRejectAudit(params).then((data) => {
                    if (data.code == '0000') {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1500,
                            onClose: () => {
                                this.visible = false;
                                this.$emit('refreshDataList');
                            }
                        });
                    }
                });
        
        }
        }
    };
</script>